package com.lizonghui.googleplay.control;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.lizonghui.googleplay.R;
import com.lizonghui.googleplay.base.BaseHolder;
import com.lizonghui.googleplay.bean.ItemInfoBean;
import com.lizonghui.googleplay.config.Constants;
import com.lizonghui.googleplay.utils.StringUtils;
import com.lizonghui.googleplay.utils.UIUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2016/6/25.
 * 模块化视图设计
 * 数据类型就仍是DetailInfoBean
 */
public class DetailInfoHolder extends BaseHolder<ItemInfoBean> {

    @Bind(R.id.app_detail_info_iv_icon)
    ImageView mAppDetailInfoIvIcon;
    @Bind(R.id.app_detail_info_tv_name)
    TextView mAppDetailInfoTvName;
    @Bind(R.id.app_detail_info_rb_star)
    RatingBar mAppDetailInfoRbStar;
    @Bind(R.id.app_detail_info_tv_downloadnum)
    TextView mAppDetailInfoTvDownloadnum;
    @Bind(R.id.app_detail_info_tv_version)
    TextView mAppDetailInfoTvVersion;
    @Bind(R.id.app_detail_info_tv_time)
    TextView mAppDetailInfoTvTime;
    @Bind(R.id.app_detail_info_tv_size)
    TextView mAppDetailInfoTvSize;

    //绑定数据data+view
    @Override
    public void refreshHolderView(ItemInfoBean data) {
        //使用带占位符的方式，而不是拼接字符的方式
        String dwonLoadNum = UIUtils.getString(R.string.detail_downnum, data.downloadNum);
        String size = UIUtils.getString(R.string.detail_size, StringUtils.formatFileSize(data.size));
        String updateTime = UIUtils.getString(R.string.detail_updatetime, data.date);
        String version = UIUtils.getString(R.string.detail_version, data.version);

        Picasso.with(UIUtils.getContext()).load(Constants.URLS.IMABASEURL + data.iconUrl).into(mAppDetailInfoIvIcon);
        mAppDetailInfoTvName.setText(data.name);
        mAppDetailInfoTvName.setTextColor(Color.BLACK);
        mAppDetailInfoRbStar.setRating((float) data.stars);
//        mAppDetailInfoTvDownloadnum.setText(data.downloadNum);
        mAppDetailInfoTvDownloadnum.setText(dwonLoadNum);
        mAppDetailInfoTvDownloadnum.setTextColor(Color.GREEN);
//        mAppDetailInfoTvVersion.setText(data.version);
        mAppDetailInfoTvVersion.setText(version);
        mAppDetailInfoTvVersion.setTextColor(Color.BLACK);
//        mAppDetailInfoTvTime.setText(data.date);
        mAppDetailInfoTvTime.setText(updateTime);
        mAppDetailInfoTvTime.setTextColor(Color.BLUE);
//        mAppDetailInfoTvSize.setText(StringUtils.formatFileSize(data.size));//应用大小转换StringUtils.formatFileSize
        mAppDetailInfoTvSize.setText(size);
        mAppDetailInfoTvSize.setTextColor(Color.BLACK);
    }


    //初始化视图,找到孩子
    @Override
    public View initHolderView() {
        View rootView = View.inflate(UIUtils.getContext(), R.layout.item_detail_info, null);
        ButterKnife.bind(this, rootView);
        return rootView;
    }
}


